﻿package net.pezzato.genetree.graphics{
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.geom.Point;
	import net.pezzato.genetree.graphics.NodeWidget;
	public class Link extends Sprite {
		public static const HEAD_POS:Point = new Point(10, NodeWidget.COMP_RECT.height / 2);
		public static const M_POS:Point = new Point(NodeWidget.COMP_RECT.width - 10, NodeWidget.COMP_RECT.height / 2 - 10);
		public static const F_POS:Point = new Point(NodeWidget.COMP_RECT.width - 10, NodeWidget.COMP_RECT.height / 2 + 10);
		private static const HMF_POS:Array = new Array(HEAD_POS, M_POS, F_POS);
		private var type_:Number;
		private var target_:Link;
		private var line_:Sprite;
		private var parentNw_:FullNodeWidget;
		public function Link(parentNw:FullNodeWidget, type:Number) {
			parentNw_ = parentNw;
			parentNw_.addChild(this);
			type_ = type;
			this.x = pos.x;
			this.y = pos.y;
		}
		public function linkTo(link:Link):void {
			if (target_ == null) {
				target_ = link;
				target_.linkTo(this);
				if (type_ > 0) {
					parentNw_.drawLink(this, link);
				}
			}
		}
		public function get globalPos():Point {
			return localToGlobal(new Point(x, y));
		}
		
		public function get line():Sprite {
			return line_;
		}
		
		public function set line(value:Sprite):void {
			line_ = value;
		}
		public function get pos():Point {
			return HMF_POS[type_];
		}
		public function get nw():NodeWidget {
			return (parent as NodeWidget);
		}
	}
}